//
//  QiPaoView.m
//  WULIHH
//
//  Created by tang on 16/3/29.
//  Copyright © 2016年 tang. All rights reserved.
//

#import "QiPaoView.h"
#import "Header.h"


#import "QiPaoCollectionViewCell.h"

@interface QiPaoView ()<UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout>
{
    UICollectionView *mainCollectionView;
    NSArray *nameArray;
    NSArray *qipaoArray;
}

@end



@implementation QiPaoView


- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        nameArray = @[@"nide.png",/* @"nidefive.png"*/ @"nidetwo.png", /*@"nidesix.png",*/ @"nidethree.png", @"nideone.png", @"nidefour.png"];
        
//        NSArray *array = @[@{@"image":@"three.png",
//                             @"width":@"127.0",
//                             @"height":@"110.0",
//                             @"frameX":@"0.0",
//                             @"frameY":@"0.0",
//                             @"jiaodu":@"0.0",
//                             @"contX":@"20.0",
//                             @"contY":@"42",
//                             @"lablewidth":@"85.0",
//                             @"lableheight":@"23.0",
//                             @"twxt":@"你的文字",
//                             @"alpha":@"1.0"}];
        
        qipaoArray = @[@{@"image":@"qqq.png",
                         @"width":@"127.0",
                         @"height":@"110.0",
                         @"jiaodu":@"0.0",
                         @"contX":@"20.0",
                         @"contY":@"42",
                         @"lablewidth":@"85.0",
                         @"lableheight":@"23.0",
                         @"twxt":@"你的文字",
                         @"alpha":@"1.0",
                         @"color":@"000000",
                         @"centerX":@"40.0",
                         @"centerY":@"50.0"},
                       
                        @{@"image":@"qqqeeewww.png",
                         @"width":@"127.0",
                         @"height":@"110.0",
                         @"jiaodu":@"0.0",
                         @"contX":@"20.0",
                         @"contY":@"42",
                         @"lablewidth":@"85.0",
                         @"lableheight":@"23.0",
                          @"twxt":@"你的文字",
                          @"alpha":@"1.0",
                          @"color":@"000000",
                          @"centerX":@"40.0",
                          @"centerY":@"50.0"},
                       
                       @{@"image":@"zuodayouxiao.png",
                         @"width":@"125.0",
                         @"height":@"110.0",
                         @"jiaodu":@"0.0",
                         @"contX":@"20.0",
                         @"contY":@"40",
                         @"lablewidth":@"85.0",
                         @"lableheight":@"23.0",
                         @"twxt":@"你的文字",
                         @"alpha":@"1.0",
                         @"color":@"000000",
                         @"centerX":@"40.0",
                         @"centerY":@"50.0"},

                        @{@"image":@"yuanxingqipao.png",
                         @"width":@"120.0",
                         @"height":@"104.0",
                         @"jiaodu":@"0.0",
                         @"contX":@"20.0",
                         @"contY":@"36.0",
                         @"lablewidth":@"77.0",
                         @"lableheight":@"22.0",
                          @"twxt":@"你的文字",
                          @"alpha":@"1.0",
                          @"color":@"000000",
                          @"centerX":@"40.0",
                          @"centerY":@"50.0"},
                       
                       @{@"image":@"zuoxiaoyoujian.png",
                         @"width":@"120.0",
                         @"height":@"104.0",
                         @"jiaodu":@"0.0",
                         @"contX":@"18.0",
                         @"contY":@"30.0",
                         @"lablewidth":@"75.0",
                         @"lableheight":@"22.0",
                         @"twxt":@"你的文字",
                         @"alpha":@"1.0",
                         @"color":@"000000",
                         @"centerX":@"40.0",
                         @"centerY":@"50.0"}];
        
//        qipaoArray = @[@{@"image":@"qqqeeewww.png",
//                         @"width":@"127.0",
//                         @"height":@"110.0",
//                         @"frameX":@"0.0",
//                         @"frameY":@"0.0",
//                         @"jiaodu":@"0.0",
//                         @"contX":@"20.0",
//                         @"contY":@"42",
//                         @"lablewidth":@"85.0",
//                         @"lableheight":@"23.0"}];

        
        [self initUI];
    }
    return self;
}





- (void)initUI
{
    
    UICollectionViewFlowLayout *flowLayout=[[UICollectionViewFlowLayout alloc] init];
    [flowLayout setScrollDirection:UICollectionViewScrollDirectionHorizontal];

    mainCollectionView =[[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, WithView, 93.0) collectionViewLayout:flowLayout];
//    [mainCollectionView setPagingEnabled:YES];
    [mainCollectionView setBackgroundColor:[UIColor clearColor]];
    [mainCollectionView setShowsVerticalScrollIndicator:NO];
    [mainCollectionView setShowsHorizontalScrollIndicator:NO];
    [self addSubview:mainCollectionView];
    [mainCollectionView setDataSource:self];
    [mainCollectionView setDelegate:self];
    
    
    [mainCollectionView registerClass:[QiPaoCollectionViewCell class] forCellWithReuseIdentifier:@"UICollectionViewCell"];
}



#pragma mark---datasource


-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return [nameArray count];
}


//每个UICollectionView展示的内容
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString * CellIdentifier = @"UICollectionViewCell";
    QiPaoCollectionViewCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath];
    [cell setTag:indexPath.row];
        [cell setIMageWithQiPao:[UIImage imageNamed:[nameArray objectAtIndex:indexPath.row]]];
//    cell.dataImage = _imageArray[indexPath.row];
//    [cell setMPhotoCollectionViewCellDelegate:self];
//    [cell setModelWith:nameIndexArray];
    
    return cell;
}
#pragma mark --UICollectionViewDelegateFlowLayout

//定义每个Item 的大小

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    return CGSizeMake(77, 77);
}

//定义每个UICollectionView 的 margin
-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
    return UIEdgeInsetsMake(0, 0, 0, 0);
}


- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section{
    
    return 5.0;
}
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section
{
    return 10.0;
}


- (void)setArray:(NSArray *)array
{
    [mainCollectionView reloadData];
}



- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    [_MQiPaoViewDelegate getQipaoImageNameInfo:qipaoArray[indexPath.row]];
}



/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
